﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XoLib.Convertion
{

    /// <summary>
    /// Convert Image to byte Array
    /// </summary>
    public class ImageToArray
    {

        /// <summary>
        /// <para>
        /// <param name="imageIn">Image</param>
        /// </para>
        /// Image To Byte Array
        /// <returns>byte[]</returns>
        /// </summary>
        public static byte[] ImageToByteArray(System.Drawing.Image imageIn)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                return ms.ToArray();
            }
        }

        /// <summary>
        /// <para>
        /// <param name="byteArrayIn">byte[]</param>
        /// </para>
        /// Center
        /// <returns>Image</returns>
        /// </summary>
        public static Image ByteArrayToImage(byte[] byteArrayIn)
        {
            using (MemoryStream ms = new MemoryStream(byteArrayIn))
            {
                Image returnImage = Image.FromStream(ms);
                return returnImage;
            }
        }
    }
}
